<!-- Created by henian.xu on 2018/11/19. -->

<template>
    <div class="goods-slider">
        <div
            class="img-obj"
            :style="`background-image: url('${data[currentIndex] || $defaultImg}');`"/>
        <div class="slider-wrap">
            <!--<div class="prev-btn f-icon">&#xf104;</div>-->
            <!--<div class="next-btn f-icon">&#xf105;</div>-->
            <div class="scroll-bar">
                <div
                    v-for="(item,index) in data"
                    :class="['item',{active:index === currentIndex}]"
                    :key="index"
                    @click="onItem(index)">
                    <div class="inner">
                        <div
                            class="img-obj"
                            :style="`background-image: url('${item||$defaultImg}');`"/>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'GoodsSlider',
    data() {
        return {
            currentIndex: 0,
        };
    },
    props: {
        data: {
            type: Array,
            default() {
                return [];
            },
        },
    },
    methods: {
        onItem(index) {
            this.currentIndex = index;
        },
    },
};
</script>

<style lang="scss">
@import '~/assets/style/_index.scss';
.goods-slider {
    > .img-obj {
        width: 100%;
        height: 0;
        padding-top: 100%;
        background: center no-repeat;
        background-size: cover;
    }
    > .slider-wrap {
        padding: $padding-small 0;
        @include clearfix;

        > .prev-btn,
        > .next-btn {
            width: 10px;
            text-align: center;
            font-size: 18px;
            margin-top: 16px;
            cursor: pointer;
        }
        > .prev-btn {
            float: left;
        }
        > .next-btn {
            float: right;
        }

        > .scroll-bar {
            white-space: nowrap;
            margin: 0 ($padding-small / -1);
            line-height: 1;
            overflow: hidden;

            > .item {
                display: inline-block;
                width: (100% / 6);
                padding: $padding-small;
                cursor: pointer;
                > .inner {
                    border: 1px solid transparent;
                    > .img-obj {
                        width: 100%;
                        height: 0;
                        padding-top: 100%;
                        background: center no-repeat;
                        background-size: cover;
                    }
                }

                &.active {
                    > .inner {
                        border-color: $color-main;
                    }
                }
            }
        }
    }
}
</style>
